package com.foxzzz.binary.search;

public class Solution367 {
    public boolean isPerfectSquare(int num) {
        int low = 0;
        int high = num;
        while (low <= high) {
            int mid = (int) ((long) (low + high) / 2);
            if (mid == num / (mid*1.0) )
                return true;
            else if (mid  < num/(mid*1.0))
                low = mid + 1;
            else
                high = mid - 1;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution367().isPerfectSquare(16));
        System.out.println(new Solution367().isPerfectSquare(14));
        System.out.println(new Solution367().isPerfectSquare(2147483647));
    }
}
